.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document.  The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\"
.\" Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
.\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 2014 Garrett D'Amore <garrett@damore.org>
.\"
.TH STRPTIME 3C "Jun 27, 2014"
.SH NAME
strptime, strptime_l \- date and time conversion
.SH SYNOPSIS
.LP
.nf
#include <time.h>

\fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR,
     \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR);
.fi
.LP
.nf
#include <time.h>
#include <xlocale.h>

\fBchar *\fR\fBstrptime_l\fR(\fBconst char *restrict\fR \fIbuf\fR,
     \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR,
     \fBlocale_t\fR \fIloc\fR);
.fi
.SS "Non-zeroing Behavior"
.LP
.nf
\fBcc\fR [\fIflag\fR...]  \fIfile\fR... \fB-D_STRPTIME_DONTZERO\fR [\fIlibrary\fR...]
#include <time.h>

\fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR,
     \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR);
.fi

.SH DESCRIPTION
.LP
The \fBstrptime()\fR function converts the character string pointed to by
\fIbuf\fR to values which are stored in the \fBtm\fR structure pointed to by
\fItm\fR, using the format specified by \fIformat\fR. The \fBstrptime_l()\fR
function is identical to \fBstrptime()\fR except instead of acting in the
current locale, it acts in the locale specified by the argument \fIloc\fR.
.LP
The \fIformat\fR argument is composed of zero or more conversion
specifications. Each conversion specification is composed of a "%" (percent)
character followed by one or two conversion characters which specify the
replacement required. One or more white space characters (as specified by
\fBisspace\fR(3C)) may precede or follow a conversion specification. There must
be white-space or other non-alphanumeric characters between any two conversion
specifications.
.LP
A non-zeroing version of \fBstrptime()\fR, described below under \fBNon-zeroing
Behavior\fR, is provided if \fB_STRPTIME_DONTZERO\fR is defined.
.SS "Conversion Specifications"
.LP
The following conversion specifications are supported:
.sp
.ne 2
.na
\fB\fB%%\fR\fR
.ad
.RS 6n
Same as \fB%\fR.
.RE

.sp
.ne 2
.na
\fB\fB%a\fR\fR
.ad
.RS 6n
Day of week, using the locale's weekday names;  either the abbreviated or full
name may be specified.
.RE

.sp
.ne 2
.na
\fB\fB%A\fR\fR
.ad
.RS 6n
Same as \fB%a\fR.
.RE

.sp
.ne 2
.na
\fB\fB%b\fR\fR
.ad
.RS 6n
Month, using the locale's month names;  either the abbreviated or full name may
be specified.
.RE

.sp
.ne 2
.na
\fB\fB%B\fR\fR
.ad
.RS 6n
Same as \fB%b\fR.
.RE

.sp
.ne 2
.na
\fB\fB%c\fR\fR
.ad
.RS 6n
Locale's appropriate date and time representation.
.RE

.sp
.ne 2
.na
\fB\fB%C\fR\fR
.ad
.RS 6n
Century number (the year divided by 100 and truncated to an integer as a
decimal number [1,99]); single digits are preceded by 0. If \fB%C\fR is used
without the \fB%y\fR specifier, \fBstrptime()\fR assumes the year offset is
zero in whichever century is specified.   Note the behavior of \fB%C\fR in the
absence of \fB%y\fR is not specified by any of the standards or specifications
described on the \fBstandards\fR(7) manual page, so portable applications
should not depend on it.  This behavior may change in a future release.
.RE

.sp
.ne 2
.na
\fB\fB%d\fR\fR
.ad
.RS 6n
Day of month [1,31]; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%D\fR\fR
.ad
.RS 6n
Date as \fB%m\fR/\fB%d\fR/\fB%y\fR.
.RE

.sp
.ne 2
.na
\fB\fB%e\fR\fR
.ad
.RS 6n
Same as \fB%d\fR.
.RE

.sp
.ne 2
.na
\fB\fB%h\fR\fR
.ad
.RS 6n
Same as \fB%b\fR.
.RE

.sp
.ne 2
.na
\fB\fB%H\fR\fR
.ad
.RS 6n
Hour (24-hour clock) [0,23];  leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%I\fR\fR
.ad
.RS 6n
Hour (12-hour clock) [1,12];  leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%j\fR\fR
.ad
.RS 6n
Day number of the year [1,366];  leading zeros are permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%m\fR\fR
.ad
.RS 6n
Month number [1,12]; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%M\fR\fR
.ad
.RS 6n
Minute [0-59]; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%n\fR\fR
.ad
.RS 6n
Any white space.
.RE

.sp
.ne 2
.na
\fB\fB%p\fR\fR
.ad
.RS 6n
Locale's equivalent of either a.m. or p.m.
.RE

.sp
.ne 2
.na
\fB\fB%r\fR\fR
.ad
.RS 6n
Appropriate time representation in the 12-hour clock format with \fB%p\fR.
.RE

.sp
.ne 2
.na
\fB\fB%R\fR\fR
.ad
.RS 6n
Time as \fB%H\fR:\fB%M\fR.
.RE

.SS "SUSv3"
.sp
.ne 2
.na
\fB\fB%S\fR\fR
.ad
.RS 6n
Seconds [0,60]; leading zero is permitted but not required. The range of values
is [00,60] rather than [00,59] to allow for the occasional leap second.
.RE

.SS "Default and other standards"
.sp
.ne 2
.na
\fB\fB%S\fR\fR
.ad
.RS 6n
Seconds [0,61]; leading zero is permitted but not required. The range of values
is [00,61] rather than [00,59] to allow for the occasional leap second and even
more occasional double leap second.
.RE

.sp
.ne 2
.na
\fB\fB%t\fR\fR
.ad
.RS 6n
Any white space.
.RE

.sp
.ne 2
.na
\fB\fB%T\fR\fR
.ad
.RS 6n
Time as \fB%H\fR:\fB%M\fR:\fB%S\fR.
.RE

.sp
.ne 2
.na
\fB\fB%U\fR\fR
.ad
.RS 6n
Week number of the year as a decimal number [0,53], with Sunday as the first
day of the week; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%w\fR\fR
.ad
.RS 6n
Weekday as a decimal number [0,6], with 0 representing Sunday.
.RE

.sp
.ne 2
.na
\fB\fB%W\fR\fR
.ad
.RS 6n
Week number of the year as a decimal number [0,53], with Monday as the first
day of the week; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%x\fR\fR
.ad
.RS 6n
Locale's appropriate date representation.
.RE

.sp
.ne 2
.na
\fB\fB%X\fR\fR
.ad
.RS 6n
Locale's appropriate time representation.
.RE

.sp
.ne 2
.na
\fB\fB%y\fR\fR
.ad
.RS 6n
Year within century. When a century is not otherwise specified, values in the
range 69-99 refer to years in the twentieth century (1969 to 1999 inclusive);
values in the range 00-68 refer to years in the twenty-first century (2000 to
2068 inclusive).
.RE

.sp
.ne 2
.na
\fB\fB%Y\fR\fR
.ad
.RS 6n
Year, including the century (for example, 1993).
.RE

.sp
.ne 2
.na
\fB\fB%Z\fR\fR
.ad
.RS 6n
Time zone name or no characters if no time zone exists.
.RE

.SS "Modified Conversion Specifications"
.LP
Some conversion specifications can be modified by the \fBE\fR and \fBO\fR
modifier characters to indicate that an alternate format or specification
should be used rather than the one normally used by the unmodified
specification. If the alternate format or specification does not exist in the
current locale, the behavior will be as if the unmodified conversion
specification were used.
.sp
.ne 2
.na
\fB\fB%Ec\fR\fR
.ad
.RS 7n
Locale's alternate appropriate date and time representation.
.RE

.sp
.ne 2
.na
\fB\fB%EC\fR\fR
.ad
.RS 7n
Name of the base year (era) in the locale's alternate representation.
.RE

.sp
.ne 2
.na
\fB\fB%Ex\fR\fR
.ad
.RS 7n
Locale's alternate date representation.
.RE

.sp
.ne 2
.na
\fB\fB%EX\fR\fR
.ad
.RS 7n
Locale's alternate time representation.
.RE

.sp
.ne 2
.na
\fB\fB%Ey\fR\fR
.ad
.RS 7n
Offset from \fB%EC\fR (year only) in the locale's alternate representation.
.RE

.sp
.ne 2
.na
\fB\fB%EY\fR\fR
.ad
.RS 7n
Full alternate year representation.
.RE

.sp
.ne 2
.na
\fB\fB%Od\fR\fR
.ad
.RS 7n
Day of the month using the locale's alternate numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%Oe\fR\fR
.ad
.RS 7n
Same as \fB%Od\fR.
.RE

.sp
.ne 2
.na
\fB\fB%OH\fR\fR
.ad
.RS 7n
Hour (24-hour clock) using the locale's alternate numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%OI\fR\fR
.ad
.RS 7n
Hour (12-hour clock) using the locale's alternate numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%Om\fR\fR
.ad
.RS 7n
Month using the locale's alternate numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%OM\fR\fR
.ad
.RS 7n
Minutes using the locale's alternate numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%OS\fR\fR
.ad
.RS 7n
Seconds using the locale's alternate numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%OU\fR\fR
.ad
.RS 7n
Week number of the year (Sunday as the first day of the week) using the
locale's alternate numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%Ow\fR\fR
.ad
.RS 7n
Number of the weekday (Sunday=0) using the  locale's alternate numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%OW\fR\fR
.ad
.RS 7n
Week number of the year (Monday as the first day of the week) using the
locale's alternate numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%Oy\fR\fR
.ad
.RS 7n
Year (offset from \fB%C\fR) in the locale's alternate  representation and using
the locale's alternate numeric symbols.
.RE

.SS "General Specifications"
.LP
A conversion specification that is an ordinary character is executed by
scanning the next character from the buffer. If the character scanned from the
buffer differs from the one comprising the specification, the specification
fails, and the differing and subsequent characters remain unscanned.
.sp
.LP
A series of specifications composed of \fB%n\fR, \fB%t\fR, white-space
characters or any combination is executed by scanning up to the first character
that is not white space (which remains unscanned), or until no more characters
can be scanned.  White space is defined by \fBisspace\fR(3C).
.LP
Any other conversion specification is executed by scanning characters until a
character matching the next specification is scanned, or until no more
characters can be scanned. These characters, except the one matching the next
specification, are then compared to the locale values associated with the
conversion specifier.  If a match is found, values for the appropriate
\fItm\fR structure members are set to values corresponding to the locale
information. If no match is found,  \fBstrptime()\fR fails and no more
characters are scanned.
.sp
.LP
The month names, weekday names, era names, and alternate numeric symbols can
consist of any combination of upper and lower case letters.  The user can
request that the input date or time specification be in a specific language by
setting the \fBLC_TIME\fR category using \fBsetlocale\fR(3C).
.SS "Non-zeroing Behavior"
.LP
In addition to the behavior described above by various standards, the Solaris
implementation of \fBstrptime()\fR provides the following extensions. These may
change at any time in the future.  Portable applications should not depend on
these extended features:
.RS +4
.TP
.ie t \(bu
.el o
If \fB_STRPTIME_DONTZERO\fR is not defined, the \fBtm struct\fR is zeroed on
entry and \fBstrptime()\fR updates the fields of the \fBtm struct\fR associated
with the specifiers in the format string.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fB_STRPTIME_DONTZERO\fR is defined, \fBstrptime()\fR does not zero the
\fBtm struct\fR on entry.  Additionally, for some specifiers, \fBstrptime()\fR
will use some values in the input \fBtm struct\fR to recalculate the date and
re-assign the appropriate members of the \fBtm struct\fR.
.RE
.LP
The following describes extended features regardless of whether
\fB_STRPTIME_DONTZERO\fR is defined or not defined:
.RS +4
.TP
.ie t \(bu
.el o
If \fB%j\fR is specified, \fBtm_yday\fR is set;  if year is given, and if month
and day are not given, \fBstrptime()\fR calculates and sets \fBtm_mon\fR,
\fBtm_mday\fR, and \fBtm_year\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fB%U\fR or \fB%W\fR is specified and if weekday and year are given and
month and day of month are not given, \fBstrptime()\fR calculates and sets
\fBtm_mon\fR, \fBtm_mday\fR, \fBtm_wday\fR, and \fBtm_year\fR.
.RE
.LP
The following describes extended features when \fB_STRPTIME_DONTZERO\fR is not
defined:
.RS +4
.TP
.ie t \(bu
.el o
If \fB%C\fR is specified and \fB%y\fR is not specified, \fBstrptime()\fRassumes
0 as the year offset, then calculates the year, and assigns \fBtm_year\fR.
.RE
.LP
The following describes extended features when \fB_STRPTIME_DONTZERO\fR is
defined:
.RS +4
.TP
.ie t \(bu
.el o
If \fB%C\fR is specified and \fB%y\fR is not specified, \fBstrptime()\fR
assumes the year offset of the year value of the \fBtm_year\fR member of the
input \fBtm struct\fR, then calculates the year and assigns \fBtm_year\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fB%j\fR is specified and neither \fB%y\fR, \fB%Y\fR, nor \fB%C\fR are
specified, and neither month nor day of month are specified, \fBstrptime()\fR
assumes the year value given by the value of the \fBtm_year\fR field of the
input \fBtm struct\fR.  Then, in addition to setting \fBtm_yday\fR,
\fBstrptime()\fR uses day-of-year and year values to calculate the month and
day-of-month, and assigns \fBtm_month\fR and \fBtm_mday\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fB%U\fR or \fB%W\fR is specified, and if weekday and/or year are not given,
and month and day of month are not given, \fBstrptime()\fR will assume the
weekday value and/or the year value as the value of the \fBtm_wday\fR field
and/or \fBtm_year\fR field of the input \fBtm struct\fR.  Then,
\fBstrptime()\fR will calculate the month and day-of-month and assign
\fBtm_month\fR, \fBtm_mday\fR, and/or \fBtm_year\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fB%p\fR is specified and if hour is not specified, \fBstrptime()\fR will
reference, and if needed, update the \fBtm_hour\fR member. If the \fBam_pm\fR
input is p.m. and the input \fBtm_hour\fR value is between 0 - 11,
\fBstrptime()\fR will add 12 hours and update \fBtm_hour\fR.  If the
\fBam_pm\fR input is a.m. and input \fBtm_hour\fR value is between 12 - 23,
\fBstrptime()\fR will subtract 12 hours and update \fBtm_hour\fR.
.RE
.SH RETURN VALUES
.LP
Upon successful completion, \fBstrptime()\fR returns a pointer to the character
following the last character parsed. Otherwise, a null pointer is returned.
.SH USAGE
.LP
Several "same as" formats, and the special processing of white-space characters
are provided in order to ease the use of identical  \fIformat\fR strings for
\fBstrftime\fR(3C) and \fBstrptime()\fR.
.LP
The \fBstrptime()\fR function tries to calculate \fBtm_year\fR, \fBtm_mon\fR,
and \fBtm_mday\fR when given incomplete input.  This allows the \fBstruct tm\fR
created by \fBstrptime()\fR to be passed to \fBmktime\fR(3C) to produce a
\fBtime_t\fR value for dates and times that are representable by a
\fBtime_t\fR.  As an example, since \fBmktime()\fR ignores \fBtm_yday\fR,
\fBstrptime()\fR calculates \fBtm_mon\fR and \fBtm_mday\fR as well as filling
in \fBtm_yday\fR when \fB%j\fR is specified without otherwise specifying a
month and day within month.
.SH ATTRIBUTES
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
CSI	Enabled
_
Interface Stability	See below.
_
MT-Level	MT-Safe
_
Standard	See \fBstandards\fR(7) for \fBstrptime()\fR.
.TE

.LP
The \fBstrptime()\fR function is Standard.  The \fBstrptime_l()\fR function
is Uncommitted.
.SH SEE ALSO
.LP
.BR ctime (3C),
.BR getdate (3C),
.BR isspace (3C),
.BR mktime (3C),
.BR newlocale (3C),
.BR setlocale (3C),
.BR strftime (3C),
.BR uselocale (3C),
.BR attributes (7),
.BR environ (7),
.BR standards (7)
